<template>
  <div class="menu-all">
    <div class="relative">
      <div :class="['menu-content', isOpen ? '':'close-menu']">
        <div class="menu-header"><slot /></div>
        <div class="menu-title"> 📑 文章目录</div>
        <ul class="menu-list">
          <li v-for="(item,index) in menuData" :key="item.viewName" @click="changeMenu(item)"><em>{{ index + 1 }}</em><span>{{ item.title }}</span></li>
        </ul>
        <TreeStyle />
      </div>
      <div :class="['mini-menu', isOpen ? '':'close-mini']" @click="miniMenuBtn">{{isOpen ? '🤛' : '🤏'}}&nbsp;&nbsp;Menu</div>
    </div>
  </div>
</template>
<script>
import TreeStyle from './TreeStyle'
export default {
  name: 'menulist',
  props: ['menuData'],
  components:{
    TreeStyle
  },
  data(){
    return {
      isOpen: false
    }
  },
  methods:{
    // 收起展开
    miniMenuBtn(){
      this.isOpen = !this.isOpen
    },
    changeMenu(item){
      this.$emit('toChangeMenu', item)
    }
  }
}
</script>
<style scoped lang="scss">
.menu-all{
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  .menu-content{
    width: 340px;
    height: 100vh;
    padding: 20px 0;
    transition: width 0.75s;
    background: rgba($color: #000000, $alpha: .5);
    border-right: 1px solid rgba($color: #000000, $alpha: .8);
    box-sizing: border-box;
    ul.menu-list{
       color: rgba($color: #ffffff, $alpha: .9);
        li{
          padding: 10px;
          cursor: pointer;
          display: flex;
          align-items: center;
          padding: 10px 20px 10px 0;
        }
        li:hover{
          background: #b30d0dbe;
          span{
            transform: scale(1.1) translateX(5px);
            font-weight: bold;
            color: rgba($color: #ffffff, $alpha: 1);
          }
        }
        li em{
          width: 40px;
          font-size: 20px;
          font-weight: bold;
          display: block;
          text-align: center;
          color: #fff;
        }
        li span{
          display: block;
          flex: 1;
          font-size: 14px;
          padding-left: 10px;
          transition: all 0.5s;
        }
        li:nth-child(1) em{
          color: #FE2D46;
        }
        li:nth-child(2) em{
          color: #F60;
        }
        li:nth-child(3) em{
          color: #FAA90E;
        }
    }
    .menu-header{
      text-align: center;
      ::v-deep span{
        border: 2px solid rgba($color: #000000, $alpha: .7);
        box-shadow: 0 0 10px rgba($color: #ffffff, $alpha: .5);
      }
    }
    .menu-title{
      width: 8em;
      color: #fff;
      font-weight: bold;
      margin: 10px auto;
      text-align: center;
      padding: 8px 5px;
      border-radius: 20px;
      border: 1px solid #fff;
    }
  }
  .close-menu{
    width: 0;
    overflow: hidden;
    max-width: 0;
    transition: width 0.75s;
  }
  .mini-menu{
    position: absolute;
    top: 0;
    z-index: 300;
    right: -100px;
    width: 100px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    background: rgba($color: #000000, $alpha: .5);
    border-radius: 0 4px 4px 0;
    border:1px solid rgba($color: #000000, $alpha: .8);
    border-left: 0;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.5s;
  }
   .mini-menu:hover{
     font-size: 16px;
   }
  .close-mini{
    top: 10px;
    right: -110px;
    border-radius: 4px;
    border-right-width: 1px;
  }
  
  ::v-deep .canvas-tree{
    bottom: 10px;
    left: 0;
    height: 30vh;
    width: 100%;
    z-index: 0;
  }
  .close-menu{
    ::v-deep .canvas-tree{
      display: none;
    }
  }
}
@media screen and (max-width: 460px) {
  .menu-content{
    width: calc(100vw - 110px) !important;
    ul.menu-list{
      height: calc(100vh - 300px);
      overflow-y: auto;
    }
  }
  ::v-deep .canvas-tree{
    height: 150px;
  }
}
</style>
